﻿using Gnivc.CarDealership.Api.Application.Abstractions;
using Microsoft.EntityFrameworkCore.Storage;

namespace Gnivc.CarDealership.Api.Infrastructure.Persistence
{
    public class UnitOfWork : IUnitOfWork
    {
        private readonly IApplicationDbContext _context;

        public UnitOfWork(IApplicationDbContext context)
        {
            _context = context;
        }

        public async Task<IDbContextTransaction> BeginTransactionAsync()
        {
            return await _context.BeginTransactionAsync();
        }

        public async Task CommitTransactionAsync()
        {
            await _context.CommitTransactionAsync();
        }

        public async Task RollbackTransactionAsync()
        {
            await _context.RollbackTransactionAsync();
        }

        public async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
        {
            return await _context.SaveChangesAsync();
        }
    }
}
